package com.cnpc.fyviewlibrary.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by songzhiiyn on 2017-03-29.
 * 不可以滑动，但是可以setCurrentItem的ViewPager。
 */

public class NoScrollViewPager extends ViewPager {
    private boolean scrollble = true;

    public NoScrollViewPager(Context context) {
        super(context);
    }

    public NoScrollViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    /**
     * 设置viewpager是否可以滑动
     */
    public void setScrollble(boolean scrollble) {
        this.scrollble = scrollble;

    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!scrollble) {
            return false;
        }
        return super.onTouchEvent(ev);
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
        if (!scrollble) {
            return false;
        }
        return super.onInterceptTouchEvent(arg0);
    }

}
